﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;

// Token: 0x02000566 RID: 1382
public class AnimationKeyInfo
{
	// Token: 0x0600215C RID: 8540 RVA: 0x0012E694 File Offset: 0x0012C894
	public virtual bool CreateInfo(int start, int end, GameObject obj, string[] usename)
	{
		if (null == obj)
		{
			return false;
		}
		Animator component = obj.GetComponent<Animator>();
		if (null == component)
		{
			return false;
		}
		this.dictInfo.Clear();
		float num = 1f / (float)(end - start);
		int num2 = end - start + 1;
		for (int i = 0; i < num2; i++)
		{
			float normalizedTime = 0f + num * (float)i;
			component.Play(component.GetCurrentAnimatorStateInfo(0).fullPathHash, 0, normalizedTime);
			component.Update(0f);
			this.CreateInfoLoop(i, obj.transform, usename);
		}
		return true;
	}

	// Token: 0x0600215D RID: 8541 RVA: 0x0012E734 File Offset: 0x0012C934
	public virtual void CreateInfoLoop(int no, Transform tf, string[] usename)
	{
		if (null == tf)
		{
			return;
		}
		List<global::AnimationKeyInfo.AnmKeyInfo> list = null;
		bool flag = false;
		if (usename != null && Array.IndexOf<string>(usename, tf.name) == -1)
		{
			flag = true;
		}
		if (!flag)
		{
			if (!this.dictInfo.TryGetValue(tf.name, out list))
			{
				list = new List<global::AnimationKeyInfo.AnmKeyInfo>();
				this.dictInfo[tf.name] = list;
			}
			global::AnimationKeyInfo.AnmKeyInfo anmKeyInfo = new global::AnimationKeyInfo.AnmKeyInfo();
			anmKeyInfo.Set(no, tf.localPosition, tf.localEulerAngles, tf.localScale);
			list.Add(anmKeyInfo);
		}
		for (int i = 0; i < tf.childCount; i++)
		{
			Transform child = tf.GetChild(i);
			this.CreateInfoLoop(no, child, usename);
		}
	}

	// Token: 0x0600215E RID: 8542 RVA: 0x0012E7F4 File Offset: 0x0012C9F4
	public virtual bool GetInfo(string name, float rate, ref Vector3 value, byte type)
	{
		return AnimationKeyInfoEx.GetInfo(this, name, rate, ref value, type);
	}

	// Token: 0x0600215F RID: 8543 RVA: 0x0012E80C File Offset: 0x0012CA0C
	public virtual bool GetInfo(string name, float rate, ref Vector3[] value, bool[] flag)
	{
		return AnimationKeyInfoEx.GetInfo(this, name, rate, ref value, flag);
	}

	// Token: 0x06002160 RID: 8544 RVA: 0x0012E824 File Offset: 0x0012CA24
	public virtual void SaveInfo(string filepath)
	{
		using (FileStream fileStream = new FileStream(filepath, FileMode.Create, FileAccess.Write))
		{
			using (BinaryWriter binaryWriter = new BinaryWriter(fileStream))
			{
				int count = this.dictInfo.Count;
				binaryWriter.Write(count);
				foreach (KeyValuePair<string, List<global::AnimationKeyInfo.AnmKeyInfo>> keyValuePair in this.dictInfo)
				{
					binaryWriter.Write(keyValuePair.Key);
					binaryWriter.Write(keyValuePair.Value.Count);
					for (int i = 0; i < keyValuePair.Value.Count; i++)
					{
						binaryWriter.Write(keyValuePair.Value[i].no);
						binaryWriter.Write(keyValuePair.Value[i].pos.x);
						binaryWriter.Write(keyValuePair.Value[i].pos.y);
						binaryWriter.Write(keyValuePair.Value[i].pos.z);
						binaryWriter.Write(keyValuePair.Value[i].rot.x);
						binaryWriter.Write(keyValuePair.Value[i].rot.y);
						binaryWriter.Write(keyValuePair.Value[i].rot.z);
						binaryWriter.Write(keyValuePair.Value[i].scl.x);
						binaryWriter.Write(keyValuePair.Value[i].scl.y);
						binaryWriter.Write(keyValuePair.Value[i].scl.z);
					}
				}
			}
		}
	}

	// Token: 0x06002161 RID: 8545 RVA: 0x0012EA64 File Offset: 0x0012CC64
	public virtual void LoadInfo(string filePath)
	{
		using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
		{
			this.LoadInfo(fileStream);
		}
	}

	// Token: 0x06002162 RID: 8546 RVA: 0x0012EAA4 File Offset: 0x0012CCA4
	public virtual void LoadInfo(string assetBundleName, string assetName)
	{
		if (!global::AssetBundleCheck.IsFile(assetBundleName, assetName))
		{
			string message = "読み込みエラー\r\nassetBundleName：" + assetBundleName + "\tassetName：" + assetName;
			global::Debug.LogError(message);
			return;
		}
		global::AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = global::AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(TextAsset), null);
		if (assetBundleLoadAssetOperation == null)
		{
			string message2 = "読み込みエラー\r\nassetName：" + assetName;
			global::Debug.LogError(message2);
			return;
		}
		TextAsset asset = assetBundleLoadAssetOperation.GetAsset<TextAsset>();
		if (null == asset)
		{
			global::Debug.LogError("ありえない");
			return;
		}
		using (MemoryStream memoryStream = new MemoryStream())
		{
			memoryStream.Write(asset.bytes, 0, asset.bytes.Length);
			memoryStream.Seek(0L, SeekOrigin.Begin);
			this.LoadInfo(memoryStream);
		}
		global::AssetBundleManager.UnloadAssetBundle(assetBundleName, true, null);
	}

	// Token: 0x06002163 RID: 8547 RVA: 0x0012EB7C File Offset: 0x0012CD7C
	public virtual void LoadInfo(Stream st)
	{
		using (BinaryReader binaryReader = new BinaryReader(st))
		{
			int num = binaryReader.ReadInt32();
			this.dictInfo.Clear();
			for (int i = 0; i < num; i++)
			{
				List<global::AnimationKeyInfo.AnmKeyInfo> list = new List<global::AnimationKeyInfo.AnmKeyInfo>();
				string key = binaryReader.ReadString();
				this.dictInfo[key] = list;
				int num2 = binaryReader.ReadInt32();
				for (int j = 0; j < num2; j++)
				{
					global::AnimationKeyInfo.AnmKeyInfo anmKeyInfo = new global::AnimationKeyInfo.AnmKeyInfo();
					anmKeyInfo.no = binaryReader.ReadInt32();
					anmKeyInfo.pos.x = binaryReader.ReadSingle();
					anmKeyInfo.pos.y = binaryReader.ReadSingle();
					anmKeyInfo.pos.z = binaryReader.ReadSingle();
					anmKeyInfo.rot.x = binaryReader.ReadSingle();
					anmKeyInfo.rot.y = binaryReader.ReadSingle();
					anmKeyInfo.rot.z = binaryReader.ReadSingle();
					anmKeyInfo.scl.x = binaryReader.ReadSingle();
					anmKeyInfo.scl.y = binaryReader.ReadSingle();
					anmKeyInfo.scl.z = binaryReader.ReadSingle();
					list.Add(anmKeyInfo);
				}
			}
		}
	}

	// Token: 0x06002164 RID: 8548 RVA: 0x0012ECDC File Offset: 0x0012CEDC
	public virtual void OutputText(string outputPath)
	{
		StringBuilder stringBuilder = new StringBuilder(2048);
		stringBuilder.Length = 0;
		foreach (KeyValuePair<string, List<global::AnimationKeyInfo.AnmKeyInfo>> keyValuePair in this.dictInfo)
		{
			for (int i = 0; i < keyValuePair.Value.Count; i++)
			{
				stringBuilder.Append(keyValuePair.Key).Append("\t");
				stringBuilder.Append(keyValuePair.Value[i].GetInfoStr());
				stringBuilder.Append("\n");
			}
		}
		using (FileStream fileStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
		{
			using (StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
			{
				streamWriter.Write(stringBuilder.ToString());
				streamWriter.Write("\n");
			}
		}
	}

	// Token: 0x04002981 RID: 10625
	protected Dictionary<string, List<global::AnimationKeyInfo.AnmKeyInfo>> dictInfo = new Dictionary<string, List<global::AnimationKeyInfo.AnmKeyInfo>>();

	// Token: 0x02000567 RID: 1383
	public class AnmKeyInfo
	{
		// Token: 0x06002166 RID: 8550 RVA: 0x0012EE4C File Offset: 0x0012D04C
		public virtual void Set(int _no, Vector3 _pos, Vector3 _rot, Vector3 _scl)
		{
			this.no = _no;
			this.pos = _pos;
			this.rot = _rot;
			this.scl = _scl;
		}

		// Token: 0x06002167 RID: 8551 RVA: 0x0012EE6C File Offset: 0x0012D06C
		public virtual string GetInfoStr()
		{
			StringBuilder stringBuilder = new StringBuilder(128);
			stringBuilder.Append(this.no.ToString()).Append("\t");
			stringBuilder.Append(this.pos.ToString("f7")).Append("\t");
			stringBuilder.Append(this.rot.ToString("f7")).Append("\t");
			stringBuilder.Append(this.scl.ToString("f7"));
			return stringBuilder.ToString();
		}

		// Token: 0x04002982 RID: 10626
		public int no;

		// Token: 0x04002983 RID: 10627
		public Vector3 pos = default(Vector3);

		// Token: 0x04002984 RID: 10628
		public Vector3 rot = default(Vector3);

		// Token: 0x04002985 RID: 10629
		public Vector3 scl = default(Vector3);
	}
}
